var errorArray=new Array();
var errorAlias=new Array();
var gbLine=0;
var currentMode=false;
var activeProfileGroup=false;
var activeUserProfile=false;
var currentPage=1;
var currentPage2=1;
var notgo=0;
var statusEditMode;
var prevDate='';
var lentaPage=1;
var lastLentaPage=2;
var spMultpl=0;
var spMultpl2=0;
var lastLentaFoto=false;
var firstLentaFoto=false;
var sb=0;
var sp=0;
var position=0;
var clicked=0;
var clickedBack=0;
var curPosit=-1;

function showComment(id)
{
	$('#showcmnt'+id).remove();
	$('#cmnt'+id).show('slow');
}

function changeHash(hassh)
{
	document.location.hash=hassh
}

function objDump (obj, except) {
	return _objDump (obj, [obj], 0);
}

function inArray (arr, elt){
	for (var i = 0; i < arr.length; i++)
	if (elt == arr[i]) return i;
	return false;
}

function _objDump (obj, used, level) {
	var rez = '';
	var spaces = "";
	for (var i = 0; i < level; i++)
	spaces += " ";
	rez += spaces+('---Dumping object: ' + obj.toString () + "n");
	for (var i in obj) {
		if (used && inArray(used ,obj[i]) !== false) {
			rez += spaces+"->"+"!Self Reference"+"n";
			continue;
		}
		rez += (spaces+"->" + i + ': ');
		if ( (typeof obj[i]) == "object"){
			try{
				rez += _objDump (obj[i], used.slice(0).push(obj[i]), 1 +level) +"n";
			}catch (eee) {rez += spaces+"->"+"!Error"+"n";}
		}
		else
		rez +=(spaces+"->"+obj[i] + "n");
	}
	return rez;
}

function setBoxValue(boxid)
{
	if ($('#'+boxid).val()==1)
	{
		$('#'+boxid).attr('value',0);

	}
	else $('#'+boxid).attr('value',1);

}

function nextGetter(plug,curr,next,opts,lntalb,position,backPosition,method)
{
	if (position>0)
	{
		waypoint = 'startPoint='+position;
	}
	else waypoint = 'backPoint='+backPosition;

	if (next.name!='last')
	{
		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg="+plug+"&plugFunc=getLentaFotos&"+waypoint+'&album='+lntalb,
			dataType:"json",
			success: function(msg)
			{
				//alert(msg.lastpage);
				lastLentaPage=msg.lastpage;
				var ul=document.createElement('div');
				ul.id='block'+position;
				ul.innerHTML=msg.result;
				if (msg.last==1)
				{
					ul.name='last';
					lastLentaFoto=true;

				}
				if (msg.first==1)
				{

					firstLentaFoto=true;
				}
				if (msg.result.length>0)
				opts.addSlide(ul,method);
				var index = opts.currSlide;
				$('#scrl_lft')[index == 0 ? 'hide' : 'show']();
				$('#scrl_rght')[index == opts.slideCount - 1 ? 'hide' : 'show']();

			}
		} );
	}
}
function getNextBlock(plug,curr, next, opts,lntalb,startPoint,startBack)
{

	$('#scrl_rght').click(function()
	{
		if (clicked<1)
		{
			clicked=clicked+1;
			startPoint = parseInt(startPoint)+sp;
			sp=sp+8;
			position = startPoint;
			method='appendTo';
			if ((!lastLentaFoto & method=='appendTo') || (!firstLentaFoto & method=='prependTo'))
			{
				nextGetter(plug,curr,next,opts,lntalb,position,0,false);
			}
		}

	}
	)
	//clicked=0;


	$('#scrl_lft').click(function()
	{
		if (clickedBack<1)
		{
			clickedBack=clickedBack+1
			method='prependTo';
			//sb=sb+8
			//startBack = parseInt(startBack)-sb;

			//position = startBack;
			if ((!lastLentaFoto & method=='appendTo') || (!firstLentaFoto & method=='prependTo'))
			{
				nextGetter(plug,curr,next,opts,lntalb,0,startBack,true)
			}
			else
			{
				return false;
			}
		}
	}
	)



}




function initStatusEditor()
{
	statusEditMode=true;
	statusDiv=document.getElementById('mystatus');
	//alert(statusDiv);
	$('p.buttstat').show();
	statusDiv.innerHTML='<input type=text id=statEditor maxlength=150 value='+'"'+statusDiv.innerHTML+'"'+'>'
	document.getElementById('saveStatus').style.display='block';
}

function editStatus(statusTxt)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=updateStatus&funcParams="+statusTxt,
		dataType:"json",
		success: function(msg)
		{

			statusDiv=document.getElementById('mystatus');
			statusDiv.innerHTML=document.getElementById('statEditor').value;
			document.getElementById('saveStatus').style.display='none';
			$('p.buttstat').hide();
			statusEditMode=false;
			if (msg.date!=0) $('#statUpd').attr('innerHTML','Обновлено '+msg.date);
			else
			{
				$('#statUpd').attr('innerHTML','');
				statusDiv.innerHTML='Изменить статус';
			}

		}
	} )


}


function getPhotoEvents(date)
{
	if (date!=prevDate)
	{
		prevDate=date;
		eventSelector = document.getElementById('eventName');
		eventSelector.innerHTML='<option value=0>Выбрать</option>';
		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg=afisha&plugFunc=getAfishaByDate&date="+date,
			dataType:"json",
			success: function(msg)
			{
				eventSelector.disabled=false;
				for (i=0; i<msg.rows.length; i++)
				{
					hoption = document.createElement('option');
					hoption.innerHTML=msg.rows[i].c_title;
					hoption.value=msg.rows[i].id;
					eventSelector.appendChild(hoption);
				}
			}
		}
		)
	}
}

function getPMs(mode,page,userFilt)
{

	currentPage=page;

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=messenger&nosmarty=1&mode="+mode+'&p='+page+'&userfilt='+userFilt,
		dataType:"json",
		success: function(msg)
		{
			$("#jTplOutput").setTemplateElement("jtplmessengermessenger");
			$("#jTplOutput").processTemplate(msg);
		}
	} )


}

function setActivePMTab(newActive)
{
	tabName=$('li.active > span').attr('innerHTML');
	$('li.active').attr('innerHTML','<a style="cursor:pointer">'+tabName+'</a>');
	$('li.active').attr('className','');
	actTabName=$('#'+newActive+' > a').attr('innerHTML');
	$('#'+newActive).attr('className','active');
	$('li.tab_active').attr('innerHTML','<span>'+actTabName+'</span>');
	//alert(tabName);

}



function recyclePM(pmid,mode,userFilt,mass,fulldel)
{

	if (fulldel==1)
	{
		delFunc = 'deleteMessage'
	}
	else delFunc = 'recycleMessage';
	decrementVal=1;
	if (mass==1)
	{
		var msgRecycle='';
		$('input[@class=delBox]:checked').each(function(i){
			$('#pmsg_'+$(this).val()).hide('slow');
			msgRecycle=msgRecycle+','+$(this).val();
			decrementVal=decrementVal+1;

		});
		msgRecycle=msgRecycle.substring(1);
		pmid=msgRecycle;
		decrementVal=decrementVal-1;
	}

	oldAmount=parseInt($('#msgTotal').attr('innerHTML').replace(' сообщений'));
	newAmount=oldAmount-decrementVal;
	$('#msgTotal').attr('innerHTML',newAmount+" сообщений");

	$('#pmsg_'+pmid).hide('slow');
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=messenger&plugFunc="+delFunc+"&funcParams="+pmid,
		dataType:"script",
		success: function(msg)
		{

			getPMs(mode,1,userFilt);
		}
	} )


}


function setPMStatus(mode,msgchecked)
{
	if (msgchecked=='')
	{
		chkBxName='viewed';
		if (mode==1) chkBxName='unviewed';
		affAmnt=0;
		$('input[@class=delBox]:checked').each(function(i){
			if ($(this).attr('name')==chkBxName)
			{
				msgchecked=msgchecked+','+$(this).val();
				if (mode==1)
				{
					$('#statPic_'+$(this).val()).hide('slow');
					$(this).attr('name','viewed');
				}
				else
				{
					$('#statPic_'+$(this).val()).show('slow');
					$(this).attr('name','unviewed');
				}

				affAmnt=affAmnt+1;
			}
		});

		msgchecked=msgchecked.substring(1);
	}
	else
	{
		if($(".delBox[value='"+msgchecked+"']").attr("name")=="viewed" && mode==1)
		{
			return false;
		}
		affAmnt=1;
		$('#statPic_'+msgchecked).hide('slow');
		$(".delBox[value='"+msgchecked+"']").attr("name", 'viewed');
	}

	oldmsgnum = parseInt($('#newMsgAmnt').attr('innerHTML'));
	if (mode==1) newAmnt = oldmsgnum-affAmnt;
	else newAmnt = oldmsgnum+affAmnt;

	if(newAmnt>0)
	{
		$('#newmsglnk').addClass("cover").text("Новые сообщения");
	}
	else
	{
		$('#newmsglnk').removeClass("cover").text("Мои сообщения");
	}

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=messenger&plugFunc=setReadStatus&funcParams="+msgchecked+'@@'+mode

	} );

}

function checkboxPM(val){
	if (val=='checkall')
	$('input.delBox').attr('checked',1);
}
function pmOptions(mode,pmode,userFilt)
{
	switch (mode)
	{
		case 'checkall': $('input.delBox').attr('checked',1); break;
		case 'recycleall':recyclePM(0,pmode,userFilt,1,0); break;
		case 'deleteall':recyclePM(0,pmode,userFilt,1,1); break;
		case 'markread': setPMStatus(1,'') ; break;
		case 'markunread': setPMStatus(0,'') ; break;
		default:break;
	}

}

function checkNewPM()
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=messenger&plugFunc=checkNewMsg",
		dataType:"json",
		success: function(msg)
		{

			if (msg.newmsg>0)
			{
				oldmsgnum = parseInt($('#newMsgAmnt').attr('innerHTML'));
				newAmnt = oldmsgnum+msg.newmsg;
				console.log(newAmnt);
				$('#newmsglnk').addClass("cover").text("Новые сообщения");

				$.jGrowl('<OBJECT classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0 WIDTH=1 HEIGHT=1><PARAM NAME=movie VALUE=/img/sndTray.swf><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src=/img/sndTray.swf quality=high bgcolor=#FFFFFF WIDTH=1 HEIGHT=1 TYPE=application/x-shockwave-flash PLUGINSPAGE=http://www.macromedia.com/go/getflashplayer></EMBED></OBJECT> Вам пришло '+msg.newmsg+' новое сообщение!');
			}
		}
	} );
}

function switchMode(mode)
{
	currentMode=mode;
	if (mode=='edit')
	{
		document.getElementById('profileMode').innerHTML="<a href=javascript:switchMode('view')>Перейти в режим просмотра</a>";
		getProfile(activeProfileGroup,'edit',activeUserProfile)
	}
	else
	{
		if (mode=='view')
		{
			document.getElementById('profileMode').innerHTML="<a href=javascript:switchMode('edit')>Редактировать профиль</a>";
			getProfile(activeProfileGroup,'view',activeUserProfile)
		}
	}

}
function getProfile(group,mode,user)
{
	activeProfileGroup=group;
	activeUserProfile=user;
	if (currentMode=='edit')
	{
		mode='edit';
	}
	document.getElementById('jTplOutput').innerHTML='<center><img src=/i/preloader.gif /></center>';
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=getProfile&prcat="+group+"&mode="+mode+"&profile="+user,
		dataType:"json",
		success: function(msg)
		{
			if (mode!='edit')
			{
				$("#jTplOutput").setTemplateElement("jtplprofile");
			}
			else
			{
				$("#jTplOutput").setTemplateElement("jtpleditprofile");
			}
			if (msg)
			$("#jTplOutput").processTemplate(msg);

		}
	} )
}

function addToFriends(friend)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=addFriend&funcParams="+friend,
		dataType:"script",
		success: function(msg)
		{
			if (msg==1)
			{
				alert('Заявко о дружбе отправлено!');
			}


		}
	} )


}

function getFriends(id,mode)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=getFriendList&mode="+mode,
		dataType:"script",
		success: function(msg)
		{
			
			if (msg)
				{

					$("#jTplOutput").setTemplateElement('jtplmyfriends');
					$("#jTplOutput").processTemplate(msg);

				}
		}
	} )
}

function delFriend(id)
{
	if (confirm('Вы действительно хотите удалить этого пользователся из друзей?'))
	{
		$('#frcounter').attr('innerHTML',parseInt($('#frcounter').attr('innerHTML'))-1);
		$('#fr'+id).hide('slow');
		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=delFriend&funcParams="+id,
			dataType:"script",
			success: function(msg)
			{
				getFriends(id,0);
			}
		} )
	}
}

function activateFriendship(candidate)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=activateFriendship&funcParams="+candidate,
		dataType:"script",
		success: function(msg)
		{
			if (msg==1)
			{
				alert('Заявко о дружбе отправлено!');
			}


		}
	} )


}



function sendPM(subj,text,to)
{
	if (text.length>0)
	{
		$.ajax(
		{
			type: "POST",
			url: "/execplugin",
			data:"plg=messenger&nosmarty=1&plugFunc=sendMessage&funcParams="+subj+'@@'+text+'@@'+to,
			dataType:"script",
			success: function(msg)
			{
				$('#dialog').jqm().jqmHide();
				$.jGrowl('Ваше сообщение отправлено!');
				$('#pmSubj').attr('value','');
				$('#pmText').attr('value','');
			}
		} )
	}
	else
	{
		alert('Нельзя отправить пустое сообщение');
	}
}


function getDirSize()
{
	$.ajax(
	{
		type: "GET",
		url: "loadbar2.php",
		dataType:"script",
		success: function(msg)
		{
			//alert(msg)

		}
	} )
}



function initSizeGetter()
{
	setInterval("getDirSize('D:/RingoProjects/newsamaranight/www/images/userAlbums/1/1')",100)
}

function deleteFriend(friend)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=delFriend&funcParams="+friend,
		dataType:"script",
		success: function(msg)
		{
			if (msg==1)
			{
				alert('Не друг ты мне больше!!!!');
			}


		}
	} )


}

function moveFileToSpecialForm()
{

}

function showUpload()
{
	$.get("loadbar2.php", function(data) {
		if (!data)
		return;

		var response;
		eval ("response = " + data);

		if (!response)
		return;

		//var percentage = Math.floor(100 * parseInt(response['bytes_uploaded']) / parseInt(response['bytes_total']));
		//$("#uploadprogressbar").progressBar(percentage);

	});
	setTimeout("showUpload()", 750);

}


function checkDbField(fldId,plg,table,dbfield,keyInErrorArr,errtxt)
{

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=CheckField&funcParams="+table+'@@'+dbfield+'@@'+$('#'+fldId).val()+'@@',
		dataType:"script",
		success: function(msg)
		{
			if (msg==1)
			{
				errorArray[keyInErrorArr]=1;
				errorAlias[keyInErrorArr]=errtxt; //ошибко
				//alert('fuck');

			}
			else
			{
				if (errorArray[keyInErrorArr]!=1)
				errorArray[keyInErrorArr]=2; //ok

			}
			lightError(fldId,keyInErrorArr,errorAlias[keyInErrorArr]);

		}
	} )




}

function postGbMsg(message,whom)
{
	value = document.getElementById('msgtext').value;
	if (value.replace(' ','').length<1)
	{
		alert ('Нельзя отправить пустое сообщение');
	}
	else
	{
		changeHash('top');
		document.getElementById('msgtext').value='';
		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg=userguestbooks&nosmarty=1&plugFunc=postMessage&funcParams="+message+'@@'+whom,
			dataType:"json",
			success: function(msg)
			{

				getGBMsg(whom,1);

			}
		})
	}
}

function checkRegex(fldId,pattern,keyInErrorArr,errtxt)
{
	if ($('#'+fldId).val().length>0)
	{
		re = new RegExp(pattern,'i');
		if (re.test($('#'+fldId).val()))
		{
			if (errorArray[keyInErrorArr]!=1)
			errorArray[keyInErrorArr]=2;
		}
		else
		{
			errorArray[keyInErrorArr]=1;
			errorAlias[keyInErrorArr]=errtxt;

		}
	}

}

function checkLength(fldId,keyInErrorArr,maxLength)
{

	if ($('#'+fldId).val().length<=maxLength)
	{
		if (errorArray[keyInErrorArr]!=1)
		errorArray[keyInErrorArr]=2;
	}
	else
	{
		errorArray[keyInErrorArr]=1;
		errorAlias[keyInErrorArr]='Превышение допустимой длины!';
	}

}

function isNotEmpty(fldId,keyInErrorArr)
{
	if ($('#'+fldId).val().length>0)
	{
		if (errorArray[keyInErrorArr]!=1)
		errorArray[keyInErrorArr]=2;
	}
	else
	{
		errorArray[keyInErrorArr]=1;
		errorAlias[keyInErrorArr]='Поле незаполнено!';
	}
}

function lightError(fldId,keyInErrorArr,errorAlias)
{
	if (errorArray[keyInErrorArr]==2)
	{
		$("#"+fldId+'Error').attr("innerHTML","<img src=/i/icon_ok.jpg>")
	}
	else
	{
		if (errorArray[keyInErrorArr])
		$("#"+fldId+'Error').attr("innerHTML","<img src=/i/icon_error.jpg> "+errorAlias)
	}

}

function registerUser()
{
	//isNotEmpty('email',0)
	//isNotEmpty('pass',3)
	//lightError('pass',3,errorAlias[3]);
	//lightError('email',0,errorAlias[0]);
	//var reg=true;
	//for (var i=0; i<errorArray.length;i++)
	//{
	//	if (errorArray[i]!=2)
	//	{
	//		reg=false;
	//	}
	//}
	//if (reg)
	//{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=registerUser&funcParams="+$('#c_email').val()+'@@'+$('#c_pass').val()+'@@'+$('#c_name').val()+'@@'+$('#c_surname').val()+'@@',
		dataType:"script",
		success: function(msg)
		{
			if (msg==1)
			{
				//document.getElementById('formContainer').style.display='none';
				document.getElementById('regForm').innerHTML='<h1>Подтвердите Ваш e-mail</h1><br><p>Спасибо за регистрацию! Вам только что ушло письмо со ссылкой активации на e-mail <b>'+$('#c_email').val()+'</b><br>Нажмите на ссылку активации, которая указана в письме для завершения регистрации.</p>';
				setTimeout(function(){$('a.jqmClose').click()},10000);
			}
			else
			{
				alert('Во время регистрации произошла ощибка. Обратитесь к администратору сайта!')
			}
		}
	} )

	//}
}

function restorePassword(email)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=restorePassword",
		data: {"email":email},
		dataType:"text",
		success: function(msg)
		{
			$(".reg").html("<h1>Проверьте свой почтовый ящик.</h1><br><p>Если адрес почты указан верно, мы вышлем вам письмо с паролем в течении 2 минут.</p>");
			setTimeout(function(){$('a.jqmClose').click()},5000);
		}
	} );

}

function editProfile()
{
	var textValues = new Array;
	var selectValues=new Array;
	var i=0;
	var n=0;
	var fldName; var fldValue='';
	$("input.editable").each(function(i)
	{

		if (this.type=='checkbox')
		{
			if (this.checked==true)
			{
				if (fldName!=this.name && fldValue!='')
				{
					textValues[n]=fldName+'='+fldValue;
					fldValue='';
					n++

				}
				fldValue = fldValue+'|'+this.value+'|';
				fldName = this.name;
			}

		}
		else
		{
			if (fldValue!='')n++;
			textValues[n]=this.name+'='+this.value;
			n++;

		}

	}
	)

	if (fldValue!='')
	textValues[i]=fldName+'='+fldValue;
	n=0;

	$("select").each(function(i)
	{
		selectValues[n]=this.name+'='+this.value;
		n++;
	}
	)
	var resultValues=textValues.concat(selectValues);
	//alert(textValues)

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=editProfile&funcParams="+resultValues,
		dataType:"script",
		success: function(msg)
		{
			alert('Profile updated')
		}
	} )
}

function setActiveTabOld(tab)
{
	for (var i=1;i<=4;i++)
	{
		document.getElementById('prtab'+i).className=document.getElementById('prtab'+i).className.replace(' tab-current','');
	}
	var theTab = document.getElementById(tab);
	//alert(tab);
	theTab.className=theTab.className+' tab-current';
}

function setActiveTab(grId)
{
	$('ul.tab_data li.tab_active a').show();
	$('ul.tab_data li').attr('className','');
	$('#grTitle').remove();
	var groupName=$('#linkgr_'+grId).attr('innerHTML');

	$('#grlist_'+grId).attr('className','tab_active');
	$('ul.tab_data li.tab_active a').hide();
	$('#grlist_'+grId).attr('innerHTML',$('#grlist_'+grId).attr('innerHTML')+'<span id=grTitle>'+groupName+'</span>');

}


function getProfile(group,mode,user)
{
	activeProfileGroup=group;
	activeUserProfile=user;
	if (currentMode=='edit')
	{
		mode='edit';
	}
	document.getElementById('jTplOutput').innerHTML='<center><img src=/i/preloader.gif></center>';
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&nosmarty=1&plugFunc=getProfile&prcat="+group+"&mode="+mode+"&profile="+user,
		dataType:"json",
		success: function(msg)
		{
			if (mode!='edit')
			{
				$("#jTplOutput").setTemplateElement("jtplprofile");
			}
			else
			{
				$("#jTplOutput").setTemplateElement("jtpleditprofile");
			}
			if (msg)
			$("#jTplOutput").processTemplate(msg);

		}
	} )
}


function getCalendar(month,year)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=jCalendar&nosmarty=1&m="+month+"&y="+year,
		dataType:"json",
		success: function(msg)
		{
			$("#jCalendDiv").setTemplateElement("jtplcalendar");
			if (msg)
			$("#jCalendDiv").processTemplate(msg);

		}
	}
	);
}

function getCalendarEvent(date)
{
	$("#vech").attr('innerHTML','<center><img src=/i/loader.gif></center>');
	if (document.getElementById('jtplthisweek'))
	{
		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg=afisha&plugFunc=getWeekAfisha&nosmarty=1&date="+date,
			dataType:"json",
			success: function(msg)
			{

				if (msg)
				{

					$("#jTplOutput").setTemplateElement('jtplthisweek');
					$("#jTplOutput").processTemplate(msg);

				}


			}
		}

		);
	}
	else document.location='/party/date.'+date+'.html';
}

function getAfisha(weekday)
{
	$("#vech").attr('innerHTML','<center><img src=/i/loader.gif></center>');
	//$('a.active').attr('className','');
	//$("#weekday_"+weekday).attr('className','active');
	if ($('a.active').attr('id'))
	{
		activeDay = parseInt($('a.active').attr('id').replace('weekday_',''));
		if (activeDay==weekday)
		{
			weekday=0;
			$('a.active').attr('className','');

		}
	}
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=afisha&plugFunc=getWeekAfisha&nosmarty=1&weekday="+weekday,
		dataType:"json",
		success: function(msg)
		{

			if (msg)
			{
				$("#jTplOutput").setTemplateElement("jtplthisweek");
				$("#jTplOutput").processTemplate(msg);
				if (weekday==1)
				{
					$("#weekday_"+weekday).attr('className','active1 active');
				}
				else
				{
					$("#weekday_"+weekday).attr('className','active');
				}

			}


		}
	}
	);
}

function getLastAfisha(weekday)
{

	$("#vech").attr('innerHTML','<center><img src=/i/loader.gif></center>');
	if ($('a.active').attr('id'))
	{
		activeDay = parseInt($('a.active').attr('id').replace('weekday_',''));
		if (activeDay==weekday)
		{
			weekday=0;
			$('a.active').attr('className','');

		}
	}
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=afisha&plugFunc=getLastWeekAfisha&nosmarty=1&weekday="+weekday,
		dataType:"json",
		success: function(msg)
		{

			if (msg)
			{
				$("#jTplOutput").setTemplateElement("jtpllastweek");
				$("#jTplOutput").processTemplate(msg);
				$("#weekday_"+weekday).attr('className','active');

			}


		}
	}
	);
}

function leaveComment(event,comment,table)
{
	if (comment.length>0)
	{
		addPreloader('ldr');
		$.ajax(
		{
			type: "POST",
			url: "/execplugin",
			data:"plg=comments&plugFunc=leaveComment&funcParams="+event+'@@'+comment+'@@'+table,
			dataType:"script",
			success: function(msg)
			{
				$('#wysiwyg').attr('value','1');
				switch(table)
				{
					case 'afishacomments':getAfishaComments(event,1,0); break;
					case 'photocomments':getPhotoComments(event,1,'cnt_photocomments');break;
					case 'inreportcomments':getPhotoComments(event,1,'cnt_inreportcomments'); break;
					case 'repocomments':getPhotoComments(event,1,'cnt_repocomments'); break;
					case 'clubcomments':getPhotoComments(event,1,'cnt_clubcomments'); break;
					case 'blogcomments':getPhotoComments(event,1,'cnt_blogcomments'); break;
					case 'reviewcomments':getReviewComments(event,1,'cnt_reviewcomments'); break;
					default: break;
				}
			}
		}
		);
	}
	else
	{
		alert('Пустое сообщение!');
	}
}

function changeHash(hashh)
{
	document.location.hash=hashh;
}
function addPreloader(divId)
{
	preLoader = document.createElement('img');
	//preLoader.src='/i/preloader.gif';
	$('#'+divId).prepend("<img src='/i/loader.gif'/>");


}
function getAfishaComments(event,page,lastMode)
{

	currentPage=page;

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=comments&plugFunc=getEventComments&nosmarty=1&p="+page+"&funcParams="+event+'@@0'+'@@'+lastMode,
		dataType:"json",
		success: function(msg)
		{

			if (msg)
			{
				$("#jTplOutput").setTemplateElement("jtplafcomments");
				$("#jTplOutput").processTemplate(msg);

			}
		}
	}
	);
}

function getReviewComments(event,page,lastMode)
{

	currentPage=page;

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=comments&plugFunc=getReviewComments&nosmarty=1&p="+page+"&id="+event,
		dataType:"json",
		success: function(msg)
		{
			console.log(msg);
			if (msg)
			{
				$("#jTplOutput").setTemplateElement("jtplreviewcomments");
				$("#jTplOutput").processTemplate(msg);

			}
		}
	}
	);
}

function getPhotoComments(event,page,table)
{

	currentPage=page;

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=comments&plugFunc=getPhotoComments&nosmarty=1&funcParams="+table+"&p="+page+"&photo="+event,
		dataType:"json",
		success: function(msg)
		{

			if (msg)
			{

				switch (table)
				{
					case 'cnt_photocomments':$("#jTplOutput").setTemplateElement("jtplphotocomments"); break;
					case 'cnt_inreportcomments':$("#jTplOutput").setTemplateElement("jtplreportcomments"); break;
					default:break;
				}

				$("#jTplOutput").processTemplate(msg);

			}
		}
	}
	);
}


function rateComment (cmnt,type,rate)
{
	$('#rateblock'+cmnt).hide();
	$('#rating'+cmnt).attr('innerHTML',parseInt($('#rating'+cmnt).attr('innerHTML').replace('+',''))+rate);
	if (parseInt($('#rating'+cmnt).attr('innerHTML').replace('+',''))>0)
	{
		$('#rating'+cmnt).attr('innerHTML','+'+$('#rating'+cmnt).attr('innerHTML'))
	}
	else
	{
		$('#rating'+cmnt).attr('className','h_red');
	}
	
$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=comments&plugFunc=setCommentRate&funcParams="+cmnt+'@@'+type+'@@'+rate,
		dataType:"json",
		success: function(msg)
		{
			alert('Preved');
			
		}
	}
	);

}
function getLatestCmnt(page)
{
	currentPage=page;
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&plugFunc=getLatestComments&nosmarty=1&p="+page,
		dataType:"json",
		success: function(msg)
		{
			if (msg)
			{
				$("#latestcmnt").setTemplateElement("jtplrepocmntfeed");
				$("#latestcmnt").processTemplate(msg);
			}
		}
	}
	);
}

function getLatestAfCmnt(page)
{
	currentPage=page;
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=comments&plugFunc=getLatestAfComments&nosmarty=1&p="+page,
		dataType:"json",
		success: function(msg)
		{
			if (msg)
			{
				$("#jtplLatestCmnt").setTemplateElement("jtplaflatestcmnt");
				$("#jtplLatestCmnt").processTemplate(msg);
			}
		}
	}
	);
}



function getPastEvents(page)
{
	currentPage=page;

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=afisha&plugFunc=getAllPastEvents&nosmarty=1&p="+page,
		dataType:"json",
		success: function(msg)
		{
			if (msg)
			{
				$("#outputOldEvents").setTemplateElement("jtploldevents");
				$("#outputOldEvents").processTemplate(msg);

			}
		}
	}
	);
}

function getAlbum(albid,page)
{
	currentPage=page;

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=useralbum&nosmarty=1&view="+albid+"&p="+page,
		dataType:"json",
		success: function(msg)
		{
			if (msg)
			{
				$("#jTplOutput").setTemplateElement("jtplviewAlbum");
				$("#jTplOutput").processTemplate(msg);


			}
		}
	}
	);
}


function igo(event)
{

	$('#vis_'+event).children(".zgo").hide();
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=afisha&plugFunc=igo&funcParams="+event,
		dataType:"json",
		success: function(msg)
		{
			$('#usercounter_'+event).attr('innerHTML',parseInt($('#usercounter_'+event).attr('innerHTML'))+1);
			$('#vis_'+event).children("#zgo_"+event).before('<a href=/mypage/ class=user_'+msg.id+'></a> ');
			$('#vis_'+event).children('.user_'+msg.id).attr('innerHTML',msg.user);
			$('#vis_'+event).children(".znotgo").show();


			$.jGrowl('Вы участник!');
		}
	}
	);
}

function idontgo(event,me)
{

	$('#vis_'+event).children(".znotgo").hide();
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=afisha&plugFunc=idontgo&funcParams="+event,
		dataType:"script",
		success: function(msg)
		{
			$('#usercounter_'+event).attr('innerHTML',parseInt($('#usercounter_'+event).attr('innerHTML'))-1);
			//alert($('#user_'+me));

			$('#vis_'+event).children('.user_'+me).remove();
			$('#vis_'+event).children(".zgo").show();

			$.jGrowl('Вы отказались от участия!');
		}
	}
	);
}


function checkMe(table,photo,x1,y1,x2,y2,user,comment,report)
{
	var checkedUsers = document.getElementById('checkedUsers');
	if (user>0 || comment.length>0)
	{

		if (user>0)comment='-1';
		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg=useralbum&plugFunc=checkUser&funcParams="+table+'@@'+photo+'@@'+x1+'@@'+y1+'@@'+x2+'@@'+y2+'@@'+user+'@@'+comment+'@@'+report,
			dataType:"json",
			success: function(msg)
			{
				if (msg.error==1) alert ('Этот пользователь уже отмечен на этой фотографии');

			}
		}
		);
	}
	else alert('Пустая отметка!');
}

function mycarousel_itemLoadCallback(carousel, state)
{
	// Check if the requested items already exist
	if (carousel.has(carousel.first, carousel.last)) {
		return;
	}

	jQuery.get(
	'/execplugin/?plg=useralbum&plugFunc=getLentaFoto',
	{
		album: $('#albumId').val(),
		start: carousel.first,
		end: carousel.last
	},
	function(xml) {
		mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
	},
	'xml'
	);
};

function mycarousel_itemLoadCallback2(carousel, state)
{
	// Check if the requested items already exist
	if (carousel.has(carousel.first, carousel.last)) {
		return;
	}

	jQuery.get(
	'/execplugin/?plg=fotoreport&plugFunc=getLentaFoto',
	{
		event: $('#albumId').val(),
		start: carousel.first,
		end: carousel.last
	},
	function(xml) {
		mycarousel_itemAddCallback2(carousel, carousel.first, carousel.last, xml);
	},
	'xml'
	);
};

function mycarousel_itemAddCallback2(carousel, first, last, xml)
{
	// Set the size of the carousel
	carousel.size(parseInt(jQuery('total', xml).text()));

	jQuery('image', xml).each(function(i) {
		carousel.add(first + i, mycarousel_getItemHTML2(jQuery(this).text()));
	});
};

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML2(url)
{
	var  urlSplit = url.split('|');
	return '<img style="cursor:pointer" id="lntImg_'+urlSplit[1]+'" src="' + urlSplit[0] + '" width="75" height="75"  onClick=setPhotoMain('+urlSplit[1]+',1,"fotoreport") />';
};


function mycarousel_itemAddCallback(carousel, first, last, xml)
{
	// Set the size of the carousel
	carousel.size(parseInt(jQuery('total', xml).text()));

	jQuery('image', xml).each(function(i) {
		carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
	});
};

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(url)
{
	var  urlSplit = url.split('|');
	return '<img style="cursor:pointer" id="lntImg_'+urlSplit[1]+'" src="' + urlSplit[0] + '" width="75" height="75"  onClick=setPhotoMain('+urlSplit[1]+',1,"userAlbums") />';
};

function incrementViews(table,photo)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=useralbum&plugFunc=incrementViews&funcParams="+table+'@@'+photo
	}
	);
}


function getNextFoto(mode,chkTable,usr)
{
	//0-вперёд,1-назад
	if (curPosit==-1) curPosit=parseInt($('#scrl_lft').attr('name'))+16;
	var currentBig = document.getElementById('mainLentaImg');
	if (mode==1) curPosit--
	else curPosit++;
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&plugFunc=getNextFoto&nosmarty=1&pos="+curPosit+"&event="+$('#albumId').val(),
		dataType:"json",
		success: function(msg)
		{
			$('#viewdevent').attr('value',msg.id);
			$('#mainLentaImg').fadeOut('slow');
			$('#mainLentaImg').attr('src',msg.src);
			$('#mainLentaImg').attr('name',msg.id);

			$('#mainLentaImg').load(function(){$('#mainLentaImg').fadeIn('slow');})
			getCheckedItems(chkTable,msg.id,usr);
			switch (chkTable)
			{
				case 'userAlbums': comntTable='cnt_photocomments' ; fotoTable='cnt_imagetoalbum'; break;
				case 'fotoreport': comntTable='cnt_inreportcomments'; fotoTable='cnt_imagetoreport'; break;
				default: break;
			}
			$('#jTplOutput').attr('innerHTML','');
			addPreloader('jTplOutput');
			getPhotoComments(msg.id,1,comntTable);
			incrementViews(fotoTable,msg.id);

		}
	} )



}
function setPhotoMain(photoId,getComments,chkTable,usr)
{
	//$('#mainLentaImg').imgAreaSelect();
	//addPreloader('inSign2');
	$('#NoteNote').attr('value','');
	$('div.notep').hide();
	$('#noteform').hide();
	$('#friendChecker').hide();

	$('#viewdevent').attr('value',photoId);


	var newSrc = $('#lntImg_'+photoId).attr('src').replace('th64','');

	if (usr!=0)
	{
		$('#mainLentaImg').attr('src',newSrc);
	}
	else
	{
		$('#mainLentaImg').attr('src','/i/unreg.jpg');
	}

	$('#mainLentaImg').attr('name',photoId);
	curPosit=parseInt($('#lntImg_'+photoId).attr('name'));
	//getCheckedUsers('userAlbums',photoId);
	getCheckedItems(chkTable,photoId,usr);
	switch (chkTable)
	{
		case 'userAlbums': comntTable='cnt_photocomments' ; fotoTable='cnt_imagetoalbum'; break;
		case 'fotoreport': comntTable='cnt_inreportcomments'; fotoTable='cnt_imagetoreport'; break;
		default: break;
	}
	incrementViews(fotoTable,photoId);
	if(getComments)
	{
		$('#jTplOutput').attr('innerHTML','');
		addPreloader('jTplOutput');
		getPhotoComments($('#viewdevent').val(),1,comntTable);
	}
	$('#mainLentaImg').imgAreaSelect({hide:true});
	//jQuery(this).data('imgAreaSelect',false);


}

function setAlbumFirst(album,photo)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=useralbum&plugFunc=setMainAlbumFoto&funcParams="+album+'@@'+photo
	}
	);
}

function getCheckedUsers(table,photoId)
{
	var checkedUsers = document.getElementById('checkedUsers');
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=useralbum&plugFunc=getCheckedUsers&funcParams="+table+'@@'+photoId,
		dataType:"json",
		success: function(msg)
		{

			if (msg)
			{

				checkedUsers.innerHTML='';
				for (i=0;i<msg.rows.length;i++)
				{
					cu=document.createElement('a');
					cu.href='javascript:showCrop('+msg.rows[i].c_x1+','+msg.rows[i].c_y1+','+msg.rows[i].c_x2+','+msg.rows[i].c_y2+')';
					cu.innerHTML=msg.rows[i].c_name +' '+ msg.rows[i].c_nick +' '+ msg.rows[i].c_surname;
					checkedUsers.appendChild(cu);
				}
			}


		}
	}
	);
}

function getCheckedItems(table,photoId,usr)
{
	var checkedUsers = document.getElementById('checkedUsers');
	//commaSpan = document.createElement('span');
	//commaSpan.innerHTML=', ';
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=useralbum&plugFunc=getCheckedItems&funcParams="+table+'@@'+photoId,
		dataType:"json",
		success: function(msg)
		{
			if (msg)
			{
				//alert(msg);
				$('.note').remove();
				$('#mainLentaImg').imgNotes(msg);
				//alert(msg);
				checkedUsers.innerHTML='';
				for (i=0;i<msg.length;i++)
				{

					//commaSpan.id='comma'+msg[i].id;


					if (msg[i]['c_userid']>0)
					{
						cu=document.createElement('a');
						//cu.href='javascript:showCrop('+msg[i].x1+','+msg[i].y1+','+msg[i].height+','+msg[i].width+')';
						cu.href='/snuser/profile.'+msg[i]['c_userid']+'.html';
						cu.innerHTML=msg[i].c_name+' '+msg[i].c_surname;
					}
					else
					{
						cu=document.createElement('span');
						cu.innerHTML=msg[i].note;
					}

					cu.id='mylabel'+msg[i].id;
					checkedUsers.appendChild(cu);
					if (usr>0)
					if (msg[i]['c_userid']==usr || msg[i]['c_checker']==usr)
					{
						var delLabelSpn = document.createElement('span');
						delLabelSpn.id='delMeLink'+msg[i].id;

						delLabelSpn.innerHTML=" <a href=javascript:deleteMyLabel("+msg[i].id+",'"+table+"',"+photoId+","+msg[i]['c_userid']+")>(Удалить)</a>";
						checkedUsers.appendChild(delLabelSpn);
					}

					checkedUsers.innerHTML=checkedUsers.innerHTML+'<span id=comma'+msg[i].id+'>,</span> ';
				}
				checkedUsers.innerHTML=checkedUsers.innerHTML.substring(0,checkedUsers.innerHTML.length-20);
			}


		}
	}
	);

}

function showCrop(xx1,yy1,xx2,yy2)
{
	alert('Function not available yet');
}

function execFotoOperation(albid,mode)
{
	if (mode=='delselected')
	{
		var fotoDel='';
		$('input[@class=imgchk]:checked').each(function(i){
			$('div[@name='+$(this).val()+']').hide('slow');
			fotoDel=fotoDel+','+$(this).val()

		});
		fotoDel=fotoDel.substring(1);


		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg=useralbum&plugFunc=deletePhotos&funcParams="+fotoDel+'@@'+albid

		}
		);

		getAlbum(albid,1)
	}
	if(mode=='setcover')
	{
		if($(".imgchk:checked").length>1)
		{
			alert("Выберите только одно изображение!");
			return false;
		}
		else if($(".imgchk:checked").length==1)
		{
			setAlbumFirst(albid, $(".imgchk:checked").val());
			$.jGrowl('Обложка альбома выбрана');
			return false;
		}
		else if($(".imgchk:checked").length==0)
		{
			alert("Выберите изображение!");
			return false;
		}
	}
}

function delAlbumPhoto(mode)
{

	if (mode=='uncheckall')
	{
		$('input.imgchk').attr('checked',0);
	}
	else if (mode=='checkall')
	{
		$('input.imgchk').attr('checked',1);
	}
}


function initEditableJS()
{
	$(document).ready(function() {

		$(".editable_name").editable("/execplugin/?plg=useralbum&plugFunc=editAlbumData", {
			indicator : "<img src='/img/indicator.gif'>",
			type   : 'text',
			submitdata: { _method: "put" },
			select : true,
			submit : 'OK',
			cancel : 'cancel',
			cssclass : "editable"
		});

		$(".editable_desc").editable("/execplugin/?plg=useralbum&plugFunc=editAlbumData", {
			indicator : "<img src='/img/indicator.gif'>",
			type   : 'textarea',
			submitdata: { _method: "put" },
			select : true,
			submit : 'OK',
			cancel : 'cancel',
			cssclass : "editable"
		});

	}
	)
}

function clickEditables(group)
{
	$('#edtdesc_'+group).click();
	$('#edttitle_'+group).click();
}

function initImgEdt()
{
	$('#selection').show('slow');
	$('input.imgchk').show();
}

function execFotoAction(mode)
{
	if (mode==2)
	{
		setAlbumFirst($('#albid').val(),$('#mainLentaImg').attr('name'));
	}
	else if (mode==1)
	{
		$.ajax(
		{
			type: "GET",
			url: "/execplugin/?plg=useralbum&plugFunc=deletePhotos&funcParams="+$('#mainLentaImg').attr('name')+'@@'+$('#albid').val()

		}
		);
		$('#mainLentaImg').attr('src','');
	}
}

function getGBMsg(owner,page)
{
	currentPage=page;
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userguestbooks&plugFunc=getGBMessages&nosmarty=1&profile="+owner+'&p='+page,
		dataType:"json",
		success: function(msg)
		{
			$("#jTplGB").setTemplateElement("jtplguestbook");
			$("#jTplGB").processTemplate(msg);

		}
	} )


}

function getUserActions(user,mode)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=eventViewer&&nosmarty=1&profile="+user+'&mode='+mode,
		dataType:"json",
		success: function(msg)
		{
			$("#jtplEvents").setTemplateElement("jtpleventViewer");
			$("#jtplEvents").processTemplate(msg);

		}
	} )


}

function publishFotos(reportId)
{
	var fotoPub='';
	var allPageFotos='';

	$('input[@class=imgchk]').each(function(i){
		allPageFotos=allPageFotos+','+$(this).val()
	});

	$('input[@class=imgchk]:checked').each(function(i){
		fotoPub=fotoPub+','+$(this).val()
	});

	fotoPub=fotoPub.substring(1);
	allPageFotos=allPageFotos.substring(1);

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&plugFunc=publishPhotos&funcParams="+fotoPub+"@@"+reportId+"@@"+allPageFotos

	}
	);
}


function delRepoFotos(reportId)
{
	var fotoPub='';

	$('input[@class=imgchk]:checked').each(function(i){
		$('#repofot_'+$(this).val()).hide('slow');
		fotoPub=fotoPub+','+$(this).val()
	});

	fotoPub=fotoPub.substring(1);

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&plugFunc=deletePhotos&funcParams="+fotoPub+"@@"+reportId

	}
	);
}

function setReportFirst(reportId)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&plugFunc=setTitleFoto&funcParams="+$('input[@class=imgchk]:checked').val()+"@@"+reportId

	}
	);
}

function execPublishOpt(mode,reportId)
{
	switch (mode)
	{
		case 'pubselected': publishFotos(reportId); break;
		case 'delselected': if (confirm('Вы уверены?')) { delRepoFotos(reportId);} break;
		case 'setTitle':
		setReportFirst(reportId);
		$.jGrowl('Обложка фотоотчёта выбрана');
		break;
		default:break;
	}

}



function getOneReport(id,page)
{
	currentPage=page;
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&plugFunc=viewReport&nosmarty=1&viewone="+id+'&p='+page,
		dataType:"json",
		success: function(msg)
		{
			$("#jTplOutput").setTemplateElement("jtplviewonereport");
			$("#jTplOutput").processTemplate(msg);

		}
	} )

}

function getReports(page)
{
	currentPage2=page;
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&nosmarty=1&p="+page,
		dataType:"json",
		success: function(msg)
		{
			$("#jTplOutput").setTemplateElement("jtplreport");
			$("#jTplOutput").processTemplate(msg);

		}
	} )

}

function getAllReports(club,fotoman)
{
	//currentPage=page;
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&nosmarty=1&club="+club+'&fotoman='+fotoman,
		dataType:"json",
		success: function(msg)
		{
			$("#jTplOutput").setTemplateElement("jtplreport");
			$("#jTplOutput").processTemplate(msg);

		}
	} )

}


function enableLightBox()
{
	$(function() {
		$('a.lightbox-enabled').lightBox();
	});
}

function getReport(event,page,fotoman)
{
	currentPage=page;

	changeHash(page);

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=fotoreport&plugFunc=viewAllReport&nosmarty=1&report="+event+"&p="+page+'&fotoman='+fotoman,
		dataType:"json",
		success: function(msg)
		{
			if (msg)
			{
				$("#jTplReport").setTemplateElement("jtplviewReport");
				$("#jTplReport").processTemplate(msg);


			}
		}
	}
	);
}

function getUserPhotos(table,user)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&plugFunc=getUserFotos&nosmarty=1&funcParams="+table+'@@'+user,
		dataType:"json",
		success: function(msg)
		{
			if (msg)
			{
				$("#jtplUserFoto").setTemplateElement("jtpluserfotos");
				$("#jtplUserFoto").processTemplate(msg);


			}
		}
	}
	);
}

function getUserFotos(mode,user,page)
{
	currentPage=page;

	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userManagement&plugFunc=getUserFotos&nosmarty=1&funcParams="+user+'@@'+mode+'&p='+page,
		dataType:"json",
		success: function(msg)
		{
			$("#jtplUserFoto").setTemplateElement("jtplalluserfotos");
			$("#jtplUserFoto").processTemplate(msg);
		}
	} )
}

function deleteAlbum(album)
{
	$('#alb'+album).hide('slow');
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=useralbum&plugFunc=deleteAlbum&nosmarty=1&funcParams="+album,
		dataType:"json",
		success: function(msg)
		{

		}
	} )
}

function deleteGBMsg(msg,owner)
{
	$('#msg'+msg).hide('slow');
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=userguestbooks&plugFunc=deleteGBMsg&nosmarty=1&funcParams="+msg,
		dataType:"script",
		success: function(msg)
		{
			getGBMsg(owner,currentPage);
		}
	} )
}

function deleteMyLabel(id,usedTable,fotoId,user)
{
	$.ajax(
	{
		type: "GET",
		url: "/execplugin/?plg=useralbum&plugFunc=removeMyLabel&nosmarty=1&funcParams="+id+'@@'+usedTable+'@@'+fotoId+'@@'+user,
		dataType:"script",
		success: function(msg)
		{
			$('#delMeLink'+id).hide();
			$('#comma'+id).hide();
			$('#mylabel'+id).hide('slow');
		}
	} )
}

// ОТЗЫВЫ
$(document).ready(function(){
	$(".reviews_type_selector").change(function(){
		var type=$(this).val();
		window.location="/reviews/type."+type+".html";
	});

	$(".addvote").click(function(){
		// голосуем
		var button=$(this);
		button.fadeOut("slow");
		$.getJSON("/execplugin/?plg=reviews&plugFunc=vote", {"review":$(this).attr("rel")}, function(data){
			if(parseInt(data)>0)
			{
				button.parents(".golos:first").find(".votes").text(data);
				button.next(".vote_result").text("Голос учтен!");
			}
			else
			{
				button.next(".vote_result").text("Вы уже голосовали!");
			}
		});
	});

	$(".submit_review").click(function(){
		var rtype=$(".look5 a p.l_act").attr("rel");
		var text=getAreaValue("wysiwyg");
		if(undefined===rtype) rtype='';
		if(rtype.length>0 && text.length>10)
		{

			$("#review_type").val(rtype);
			$("#review_text").val(text);
			$("#write_comment").submit();
		}
		else
		{
			alert("Возможно вы не выбрали тип вашего отзыва либо ваше сообщение слишком короткое.");
		}
		return false;
	});

	$(".submit_comment_to_review").click(function(){
		var text=getAreaValue("wysiwyg");
		if(text.length>5)
		{
			$("#review_text").val(text);
			leaveComment($('.addvote:first').attr("rel"),text,'reviewcomments');
			resetArea("wysiwyg");
			//$("#write_comment").submit();

		}
		else
		{
			alert("Возможно, ваше сообщение слишком короткое...");
		}
		return false;
	});

	$(".look5 a p").click(function(){
		$(".look5 a p").removeClass("l_act");
		$(this).addClass("l_act");
		return false;
	});
	
});

function delete_blog(elem)
{
	if(confirm("Вы действительно желаете удалить эту запись блога?"))
	{
		var blog_id=$(elem).attr("rel");
		console.log($(elem).attr("rel"));
		$.getJSON("/execplugin/?plg=blog&plugFunc=deleteBlog", {id:blog_id}, function(response){
			if(parseInt(response)>0)
			{
				$(elem).parents(".part1:first").hide("slow");
			}
			else
			{
				alert("Возникла ошибка при удалении блога.");
			}
		});
	}
	return false;
}